package com.bcst.service.impl;

import com.bcst.dao.AccountDao;
import com.bcst.entity.Account;
import com.bcst.service.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/*
 *@description 欢迎关注公众号 编程识堂,每日更新技术相关文章，关注我不迷路
 *@author 小堂
 *@create 2023/9/2 16:13
 */
@Service("transferService")
public class TransferServiceImpl implements TransferService {

    @Autowired
    @Qualifier(value = "accountDao")
    private AccountDao accountDao;

    public Boolean transfer(String fromCardNo, String toCardNo, int money)
            throws Exception {
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);
            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);
            accountDao.updateAccountByCardNo(from);
            accountDao.updateAccountByCardNo(to);
            return true;
    }
}

